package com.cctc.rds.scheduler.client;

import com.cctc.rds.scheduler.client.worker.PrintTask;
import com.cctc.rds.scheduler.client.schedule.TaskScheduleClient;
import com.cctc.rds.scheduler.core.task.Task;
import com.cctc.rds.scheduler.core.task.TaskFactory;

import java.util.Random;

public class PrintScheduler {

    public static void main(String[] args) {
        SchedulerClientApplication.start(
                "print",
                "127.0.0.1:9001,127.0.0.1:9002,127.0.0.1:9003",
                1000,
                1500
        );
        for (int i = 0; i < 26; i++) {
            String taskName = "print-task-" + ((char) 'a' + i);
            Task<String> printTask = new PrintTask(taskName);
            TaskFactory.putTask("print-task", taskName, printTask);
            try {
                TaskScheduleClient taskScheduleClient = SchedulerClientApplication.getTaskScheduleClient();
                long taskId = taskScheduleClient.submit(printTask, 0, 2, 4, 8, 12, 16, 20);
                System.out.println("task " + taskName + " id is " + taskId);
            } catch (Throwable e) {
                e.printStackTrace();
            }
            try {
                Thread.sleep(5000 + new Random().nextInt(100));
                System.in.read();
            } catch (Exception e) {
            }
        }
    }

}
